package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Promotionaloffer;
import com.restaurant.service.PromotionalofferService;

public class PromotionalofferServiceImpl implements PromotionalofferService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffer addOrModify( Promotionaloffer objPromotionaloffer ) {
       return ( Promotionaloffer ) hibernateTemplate.merge( objPromotionaloffer );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffer deleteRecord( Promotionaloffer objPromotionaloffer ) {
       hibernateTemplate.delete( objPromotionaloffer );
       return objPromotionaloffer;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffer modifyRecord( Promotionaloffer objPromotionaloffer ) {
       return ( Promotionaloffer ) hibernateTemplate.merge( objPromotionaloffer );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Promotionaloffer> loadAll() {
       return (List<Promotionaloffer>)hibernateTemplate.findByNamedQuery( "Promotionaloffer.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffer loadByPrimaryKey( Long primaryKey ) {
       return (Promotionaloffer) hibernateTemplate.get( Promotionaloffer.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffer deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Promotionaloffer> loadByHql(String query) {
       return ( List<Promotionaloffer> ) hibernateTemplate.find( query );
   }
}